package org.jsola.hr.provider.impl;

import lombok.extern.slf4j.Slf4j;
import org.jsola.contract.dto.MemberVariableDTO;
import org.jsola.contract.vo.ContractVO;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

import java.util.concurrent.CountDownLatch;

@Component
@Slf4j
public class AsyncContractProvider {

    @Async
    public ContractVO demoAsync(MemberVariableDTO memberVariableDTO, CountDownLatch countDownLatch) {
        try {
            log.info("demoAsync线程：{}，开始时间",Thread.currentThread().getName(),System.currentTimeMillis());
            //随机0-3秒延迟，模拟真实业务
            Thread.sleep((long)Math.random()*3000);
            ContractVO contractVO = new ContractVO();
            contractVO.setId(System.currentTimeMillis());
            countDownLatch.countDown();
            log.info("demoAsync线程：{}，结束时间",Thread.currentThread().getName(),System.currentTimeMillis());
            return contractVO;
        } catch (InterruptedException e) {
            log.error("demoAsync error", e);
            return null;
        }
    }

}
